package com.hnao.hnserialport

import android.app.Application
import com.hnao.serialport.SerialPortApplicationManager
import com.hnao.serialport.SerialPortCallbackListener

/**
 * @Author caow
 * 2025/2/19
 */
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        SerialPortApplicationManager.init()
        SerialPortCallbackListener.setListener {
            listener?.invoke(it)
        }
    }

    override fun onTerminate() {
        SerialPortCallbackListener.setListener(null)
        super.onTerminate()
    }

    private var listener: ((String) -> Unit)? = null

    fun setListener(listener: ((String) -> Unit)?) {
        this.listener = listener
    }
}